var fs = require('fs');
var https = require('https');
var express =require('express');

var key =fs.readFileSync('ssl/server.key.pem','utf8');
var cert =fs.readFileSync('ssl/server.cert.pem','utf8');
var pfx = fs.readFileSync('ssl/server.pfx','utf8');

//服务器部分
var options = {ca: ca, key: privateKey, cert: certificate};
var httpsServer = https.createServer(options,function (req,res) {
    res.writeHead(200);
    res.end();
});
httpsServer.listen(443,'localhost',function () {
   console.log("监听443");
});


//客户端部分demo   https端口 443
var options ={
    hostname:'xxxx',
    port:443,
    path:'/',  //path拼接看业务
    method:'GET',
    key:fs.readFileSync('ssl/server.key.pem'), //私钥 下面设置了utf8
    cert:fs.readFileSync('ssl/server.cert.pem'),
    agent:false
};
//客户端部分如果在wins上要写1个config({绝对路径pem.exe})

//下面可以抽象到另外1个文件内，然后下面用Client.prototype.request
var req =https.request(options,function (res) {
   //拿到headers后可以用来拼装https请求的部分，写在headers里
    console.log('状态码:'+ res.statusCode,'heads:'+JSON.stringify(res.headers));
    res.setEncoding('utf8');
    res.on('data',function (chunk) {
        console.log('回包:'+chunk);
    });
    res.on('error',function (err) {
        console.log(err.message);
    });
});
req.end();